package com.beiyou.controller;

import java.util.*;
import cn.hutool.core.util.ObjectUtil;
import com.beiyou.dto.UserInfo;
import com.beiyou.dto.VendorDtoQuery;
import com.beiyou.local.UserInfoLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.beiyou.service.VendorService;
import com.beiyou.dto.VendorDto;

/**
 * 
 *
 * @author wzby
 * @date 2022-10-31 20:49:20
 */
@RestController
@RequestMapping("/api/vendor")

public class VendorController {

    @Autowired
    private VendorService vendorService;

    @GetMapping
    public List<VendorDto> select(VendorDtoQuery vendorDtoQuery){
        return vendorService.select(vendorDtoQuery);
    }

    @PostMapping
    public Integer insert(@RequestBody VendorDto vendorDto){
        UserInfo userInfo = UserInfoLocal.get();
        vendorDto.setLastUpdateBy(userInfo.getNickName());
        return vendorService.insert(vendorDto);
    }
    @PatchMapping
    public Integer statusUpdate(@RequestBody Map<String,Integer> map){
        Integer id = map.get("id");
        Integer status = map.get("status");
        return vendorService.statusUpdate(id,status);
    }

    @PutMapping
    public Integer update(@RequestBody VendorDto vendorDto){
        UserInfo userInfo = UserInfoLocal.get();
        vendorDto.setLastUpdateBy(userInfo.getNickName());
        return  vendorService.update(vendorDto);
    }

    @DeleteMapping("/{id}")
    public Integer delete(@PathVariable  Integer id){
        return vendorService.delete(id);
    }
}
